package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.Admin;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.MarketFeedback;
import com.cskaoyan.bean.User;
import com.cskaoyan.exception.ValidationException;
import com.cskaoyan.service.wx.WxFeedbackService;
import com.cskaoyan.util.GetLogedAdmin;
import com.cskaoyan.util.GetLogedUser;
import com.cskaoyan.util.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @author Kongwo
 * @description
 * @since 2022/05/09 19:42
 */

@RestController
@RequestMapping("wx/feedback")
public class WxFeedbackController {

    @Autowired
    WxFeedbackService wxFeedbackService;

    @PostMapping("submit")
    public BaseRespVo feedbackSubmit(@Validated @RequestBody MarketFeedback marketFeedback, BindingResult bindingResult, HttpSession session) throws ValidationException {
        Integer userId = GetLogedUser.getUserId();
        if (userId == 0) {
            return new BaseRespVo("请登录",501);
        }


        ValidationUtil.valid(bindingResult);

        wxFeedbackService.submitFeedback(marketFeedback, userId);
        return BaseRespVo.ok(null);
    }
}
